package com.lk.api.own;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MyExpandableListView extends ExpandableListActivity {

	private static final String NAME = "NAME";
	private static final String IS_EVEN = "is_even";
	private ExpandableListAdapter mAdapter;

	OnClickListener clickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Toast.makeText(MyExpandableListView.this,
					"" + ((TextView) v).getText(), 2000).show();

		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		// �������Դ
		// List<Map<String, String>> groupData = new ArrayList<Map<String,
		// String>>();
		//
		// List<List<Map<String, String>>> childData = new
		// ArrayList<List<Map<String, String>>>();
		//
		// for (int i = 0; i < 20; i++) {
		// Map<String, String> curGroupMap = new HashMap<String, String>();
		// groupData.add(curGroupMap);
		// curGroupMap.put(NAME, "Group " + i);
		// curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" :
		// "This group is odd");
		//
		// List<Map<String, String>> children=new
		// ArrayList<Map<String,String>>();
		// for (int j = 0; j < 15; j++) {
		// Map<String, String> curChildMap=new HashMap<String, String>();
		// children.add(curChildMap);
		// curChildMap.put(NAME, "Child" + j);
		// curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" :
		// "This child is odd");
		// }
		// childData.add(children);
		//
		// }
		// // Set up our adapter
		// mAdapter=new SimpleExpandableListAdapter(
		// this,
		// groupData,
		// android.R.layout.simple_expandable_list_item_1,
		// new String[] { NAME, IS_EVEN },
		// new int[] { android.R.id.text1, android.R.id.text2 },
		// childData,
		// android.R.layout.simple_expandable_list_item_2,
		// new String[] { NAME, IS_EVEN },
		// new int[] { android.R.id.text1, android.R.id.text2 }
		// );
		// setListAdapter(mAdapter);

		// �������Դ �����list
		List<HashMap<String, String>> groupData = new ArrayList<HashMap<String, String>>();
		// List<Map<String, String>> groupData = new ArrayList<Map<String,
		// String>>();
		// �������Դ �����list
		// List<List<Map<String, String>>> childData = new
		// ArrayList<List<Map<String, String>>>();
		List<List<HashMap<String, String>>> childData = new ArrayList<List<HashMap<String, String>>>();

		for (int i = 0; i < 20; i++) {

			// Map<String, String> curGroupMap = new HashMap<String, String>();
			HashMap<String, String> curGroupMap = new HashMap<String, String>();

			groupData.add(curGroupMap);
			curGroupMap.put(NAME, "Group " + i);
			// curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" :
			// " This group is odd");

			// List<Map<String, String>> children = new ArrayList<Map<String,
			// String>>();
			List<HashMap<String, String>> children = new ArrayList<HashMap<String, String>>();
			for (int j = 0; j < 1; j++) {

				// Map<String, String> curChildMap = new HashMap<String,
				// String>();
				HashMap<String, String> curChildMap = new HashMap<String, String>();
				children.add(curChildMap);
				curChildMap.put(NAME, "Child " + j);
				curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even"
						: " This child is odd");
			}
			childData.add(children);
		}
		// ����adapter�����Ұ����Դ
		mAdapter = new SimpleExpandableListAdapter(this, groupData,
				android.R.layout.simple_expandable_list_item_1, new String[] {
						NAME, IS_EVEN }, new int[] { android.R.id.text1,
						android.R.id.text2 }, childData,
				android.R.layout.simple_expandable_list_item_2, new String[] {
						NAME, IS_EVEN }, new int[] { android.R.id.text1,
						android.R.id.text2 });
		// ��ui
		setListAdapter(mAdapter);

	}

}
